package com.zhaoyh.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;


public class PoiUtil {
    /**
     * 读取word文件内容	 * 	 * @param path	 * @return buffer
     */
    public static String readWord(String path) {
        String buffer = "";
        try {
            if (path.endsWith("docx")) {
                OPCPackage opcPackage = POIXMLDocument.openPackage(path);
                POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
                buffer = extractor.getText();
                extractor.close();
            } else {
                System.out.println("此文件不是word文件！");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return buffer;
    }

    public static void  main(String[] args) {
//        System.out.print(readWord("D:" + File.separator +"resume" + File.separator + "resume.docx"));
        File file = new File("http://www.aicxb.com/resume.docx");
        System.out.print(readWord(file.getPath()));
    }
}
